Page({
  data: {
    images: []
  },
  onLoad: function (options) {
    const categoryId = options.id;
    if (categoryId) {
      this.getCategoryDetails(categoryId);
    }
  },
  getCategoryDetails: function (id) {
    const that = this;
    wx.request({
      // !! 重要: 请确保这里的地址是你后台服务的地址
      url: `http://43.142.120.23:5000/api/categories/${id}`, 
      method: 'GET',
      success: function(res) {
        if (res.statusCode === 200) {
          wx.setNavigationBarTitle({
            title: res.data.name
          });
          that.setData({
            images: res.data.images
          });
        }
      },
      fail: function() {
        wx.showToast({
          title: '加载详情失败',
          icon: 'none'
        });
      }
    });
  }
});